﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_309_07
    {
        //图F.98  ISYC 309-07-法兰接触式连接的可转位刀片外车削系统
        public static void ISYC_309_07_g(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
            //      double sl_ = 45;
            //      double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dconms = 10*scale ;
            double wf = 6.37*scale ;
            double wfa = 3.47 * scale;
            double lf = 12.41 * scale;
            double lpr = 13.33 * scale;
            double oal = 18.73 * scale;
            double kapr = 75;
            double kapr_ = kapr * pi / 180;
            double lfa = lpr - lf;*/

            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double wfa = Convert.ToDouble(data["wfa"]) * scale;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lpr = Convert.ToDouble(data["lpr"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]);
            double kapr_ = kapr * pi / 180;
            double lfa = lpr - lf;
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //柄部
            Vector2 p0 = new Vector2(0, 0);
            Vector2[] vis(Vector2 p)
            {
                Vector2 p1_0; Vector2 p2_0; Vector2 p3_0; Vector2 p4_0; Vector2 p5;
                p1_0 = fun.Polar(p, pi / 2, dconms / 2.0);
                p2_0 = fun.Polar(p, pi / -2, dconms / 2.0);
                p3_0 = fun.Polar(p2_0, pi, 4.2 / 19.54 * lpr);
                p4_0 = fun.Polar(p1_0, pi, fun.CalDistance(p2_0, p3_0));
                p5 = fun.Polar(p3_0, pi / 2, dconms / 12.5);
                Vector2 p6 = fun.Polar(p5, pi - 5 * pi / 180, ((oal - lpr) / Math.Cos(5 * pi / 180)) - ((0.4 / 4.96) * (oal - lpr)));
                Vector2 p7_0 = fun.Polar(fun.Polar(p5, pi / 2, fun.CalDistance(p4_0, p5) / 2.0), pi, oal - lpr);
                Vector2 p7_1 = fun.Polar(p7_0, pi / 2, dconms);
                Vector2 p7_2 = fun.Polar(p7_0, pi / -2, dconms);
                Vector2 p7_3 = fun.Polar(p6, fun.CalAngle(p5, p6) - pi / 4, dconms);
                Vector2 p7_4 = fun.Inters(p6, p7_3, p7_1, p7_2);
                Vector2 p8_0 = fun.Polar(p4_0, pi / -2, fun.CalDistance(p3_0, p5));
                Vector2 p9_0 = fun.Polar(p8_0, pi + 5 * pi / 180, fun.CalDistance(p5, p6));
                Vector2 p10_0 = fun.Polar(p9_0, (-fun.CalAngle(p6, p7_4)), fun.CalDistance(p6, p7_4));
                var polyline1 = Pus.AddPointsToLwPolyLine(p8_0, p4_0, p1_0, p2_0, p3_0, p8_0, p9_0, p10_0, p7_4, p6, p9_0, p6, p5);
                Line line2 = new Line(fun.Polar(p, pi, p1_0.X + (oal - lpr) + 15), fun.Polar(p, 0, lpr + 15));
                line2.Lineweight = Lineweight.W25;//Lineweight指线宽
                line2.Layer = centre  ;//Layer指图层
                line2.LinetypeScale = 5 * scale;//指线性比例
                if(p.Y ==0)
                line2.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                else
                line2.Linetype = Linetype.DashDot ;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line2); //提取
                fun.PolyFill(dxf, polyline1, 0.5, contour);
                Vector2[] pj = { p1_0, p2_0, p3_0, p4_0,p5,p6, p7_4, p8_0, p9_0 ,p10_0 };
                return pj;
            }

            Vector2[] pj_1 = vis(p0);
            Vector2 p1 = pj_1[0];
            Vector2 p2 = pj_1[1];
            Vector2 p3 = pj_1[2];
            Vector2 p4 = pj_1[3];

            Vector2 p11 = fun.Polar(p2, pi/-2, fun.CalDistance(p1, p2) * (0.6 / 10.0));
            Vector2 p12 = fun.Polar(p1, 0, fun.CalDistance(p1, p4) * (0.57 / 3.68));
            Vector2 p13 = new Vector2(-fun.CalDistance(p1, p4) + lpr - lfa / 2.0,0);
            Vector2 p14 = fun.Polar(p13, pi, lpr * (6.766 / 13.22));
            Vector2 p15 = fun.Polar(p13, pi / -2, (1.13 / 10.0) * dconms);
            Vector2 p16 = fun.Polar(p15, pi, (0.37 / 13.22) * lpr);
            Vector2 p17 = fun.Polar(p16, -97 * pi / 180, dconms * (1.71 / 10.0));
            Vector2 p18_1 = fun.Polar(p11, 0, lpr);
            Vector2 p18_2 = fun.Polar(p17, -112 * pi / 180, lpr);
            Vector2 p18 = fun.Inters(p11, p18_1, p17, p18_2);
            Vector2 p19 = fun.Polar(p13, pi, (2.79 / 13.22) * lpr);
            Vector2 p20 = fun.Inters(p19, fun.Polar(p19, pi / -2, dconms), p11, p18);
            Vector2 p21 = fun.Polar(p14, 0, (1.63 / 13.22) * lpr);
            Vector2 p22 = fun.Inters(p11, p18, p21, fun.Polar(p21, pi / -2, dconms));
            Vector2 p23 = fun.Polar(p21, pi, (0.92 / 13.22) * lpr);
            Vector2 p24 = fun.Inters(p11, p18, p23, fun.Polar(p23, pi / -2, dconms));
            Vector2 p25 = fun.Inters(p19, p20, p15, fun.Polar(p15, pi, dconms));
            Vector2 p26 = fun.Polar(p13, pi, (0.89 / 13.22) * lpr);
            Vector2 p27 = fun.Inters(p25, p15, p26, fun.Polar(p26, pi / -2, dconms));
            Vector2 arc1_1 = fun.Polar(p23, pi, fun.CalDistance(p11, p24) / 3.0);
            Vector2 arc1_2 = fun.Polar(arc1_1, pi - pi / 3, dconms);
            

            //第二部分
            //柄部
            Vector2 p0_0 = fun.Polar(p0, pi / -2, dconms * 2);
            Vector2[] pj_2 = vis(p0_0);
            Vector2 p1_10 = pj_2[0];
            Vector2 p2_10 = pj_2[1];
            Vector2 p3_10 = pj_2[2];
            Vector2 p4_10 = pj_2[3];
            Vector2 p5_10 = pj_2[4];
            Vector2 p6_10 = pj_2[5];
            Vector2 p7_10 = pj_2[6];
            Vector2 p8_10 = pj_2[7];
            Vector2 p9_10 = pj_2[8];
            Vector2 p10_10 = pj_2[9];
            Vector2 p28 = new Vector2(-fun.CalDistance(p1, p4) + lpr - lfa / 2.0,p0_0.Y );
            Vector2 p29 = fun.Polar(p28, pi / 2, (0.67 / 10.0) * dconms);
            Vector2 p30_1 = fun.Polar(p29, pi - pi / 4, dconms);
            Vector2 p30_2 = fun.Polar(p1_10, 0, dconms);
            Vector2 p30 = fun.Inters(p1_10, p30_2, p29, p30_1);
            Vector2 p31 = fun.Polar(p2_10, pi / -6, (1 / 13.33) * lpr);
            Vector2 p32_1 = fun.Polar(p28, pi / -2, dconms);
            Vector2 p32_2 = fun.Polar(p31, 0, dconms);
            //切削部分
            Vector2 p32 = fun.Inters(p31, p32_2, p28, p32_1);
            Vector2 p33 = fun.Polar(p32, pi - pi / 4, (wfa / 4.0) / Math.Cos(pi / 4));
            Vector2 p34 = fun.Polar(p33, pi / 2 - pi / 4 - (pi / 2 - kapr_), (wfa / 2.0) / (Math.Cos(pi / 4)));
            Vector2 p35 = fun.Polar(p34, kapr_ - pi, wfa);
            Vector2 p36 = fun.Polar(p35, fun.CalAngle (p35, p34) + pi / 2, wfa);
            Vector2 p37 = fun.Polar(p36, fun.CalAngle (p36, p35) + pi / 2, wfa);
            Vector2 p38 = fun.Inters(p34, p37, p28, fun.Polar(p28, pi / -2, dconms));
            Vector2 p39 = fun.Inters(p36, p37, p31, fun.Polar(p31, 0, dconms));


            Arc arc1 = fun.DrawArc5(p12, new Line(arc1_1, arc1_2), p14);
            var polyline2 = Pus.AddPointsToLwPolyLine(p12, p1, p11, p24, p23, p21, p22, p24, p20, p19, p13, p15, p27,p25,p27,
                p26, p19, p20, p18, p17, p16, p15, p13, p14);
            var polyline3 = Pus.AddPointsToLwPolyLine(p1_10,p30,p29,p38,p37,p36,p35,p34,
              p37,p39,p31,p2_10 );
           /*dxf.AddEntity(new EntityObject[] { polyline2,polyline3,
                arc1 
            });*/
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            //标注
            /* fun.dimrot1(dxf, p1, p18, 90, dc, 2, 2 * scale, 2.4 * scale, 0.9, "DCB", "", "");
       fun.jdbz2(dxf, new Line(p4, p5), new Line(p7, p8), dc, 2 * scale, 2.4 * scale, 0.9, "SIG", "", "");
       fun.Axis(dxf, fun.Polar(p0, pi + pi / 3, dc * 2), 180, -90, "Z", "X", "Y", 1 * scale, 2 * scale, 0);
       fun.Axis(dxf, p0, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
       fun.Axis(dxf, p19, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
       fun.Singlelinearrow(dxf, "CCMS", v1, 110, fun.Polar(v1, 110 * pi / 180, dc / 2.0), fun.Polar(v1, 110 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
       Text txt1 = new Text("PCS", v18, 2.2 *scale , 0);
       Circle circle1 = new Circle(p0, 1.7 * 2 * scale) ;
             */
            Vector2 v1 = fun.Polar(p3, pi / 2, fun.CalDistance(p3, p4) / 2.0);
            Vector2 v2 = fun.Polar(p19, 0, fun.CalDistance(p19, p26) / 2.0);
            Vector2 v3 = fun.Polar(p3_10, pi / 2, fun.CalDistance(p3, p4) / 2.0);
            Vector2 v4 = fun.Polar(p9_10, fun.CalAngle(p9_10, p8_10), fun.CalDistance(p9_10, p8_10) * (2 / 3.0));
            Vector2 v5 = fun.Polar(p35, pi / -6, dconms * 1.5);
            Vector2 v6 = fun.Polar(v1, pi + 80 * pi / 180, 0.2 * 1.7 * scale) ;
            Vector2 v7 = fun.Polar(v6, pi + 80 * pi / 180, (fun.CalDistance(v1, v3) / 2.0) / (Math.Cos(10 * pi / 180)));
            Vector2 v8 = fun.Polar(v7, pi / -2, 0.8 * scale);
            Vector2 v9 = fun.Polar(v3, pi / 2 + 10 * pi / 180, 0.2 * 1.7 * scale);
            Vector2 v10 = fun.Polar(v2, pi - pi / 4, 0.2 * 1.7 * scale);
            Vector2 v11 = fun.Polar(v10, pi - pi / 4, dconms / 2.0);
            Vector2 v12 = fun.Polar(p26, pi / -4, 0.2 * 1.7 * scale);
            Vector2 v13 = fun.Polar(v12, pi / -4, dconms / 2.0);
            Vector2 v14 = fun.Polar(v13, pi / -2, 0.8 * scale);
            Vector2 v15 = fun.Polar(p33, pi + pi / 4, 0.2 * 1.7 * scale);
            Vector2 v16 = fun.Polar(v15, pi + pi / 4, dconms / 2.0);
            Vector2 v17 = fun.Polar(v16, pi / -2, 0.8 * scale);
            Vector2 v18 = fun.Polar(p35, pi + pi / 4, 0.2 * 1.7 * scale);
            Vector2 v19 = fun.Polar(v18, pi + pi / 4, dconms / 2.0);
            Vector2 v20 = fun.Polar(v19, pi / -2, 0.8 * scale);

            fun.dimrot1(dxf, p26, fun .Polar (p26,pi/-2,0.1), -90, dconms /2.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "HF,HTA", "", "");
            fun.dimrot1(dxf, p3_10, p4_10 , 90, dconms , 2, 0.8 * scale, 1.2 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p28, p35, -90, dconms , 2, 0.8 * scale, 1.2 * scale, 0.9, "WFA", "", "");
            fun.dimrot1(dxf, p34 , p35 , -90, dconms / 2.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "WF,WTA", "", "");
            fun.dimrot1(dxf, p35, p34 , 180, dconms*1.5 +((p35.Y -p34 .Y )/2.0)+(p34.Y -p28 .Y ) , 2, 0.8 * scale, 1.2 * scale, 0.9, "LFA", "", "");
            fun.dimrot1(dxf, p3_10, p35 , 180, dconms*1.5  + ((p35.Y - p3_10.Y)/2.0) + (p3_10.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LF,LTA", "", "");
            fun.dimrot1(dxf, p3_10, p34, 180, dconms * 1.8 + ((p3_10.Y - p34.Y) / 2.0) + (p34.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p7_10, p34, 180, dconms * 2.0 + ((p7_10.Y - p34.Y) / 2.0) + (p34.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "OAL", "", "");
            fun.jdbz2(dxf, new Line(p35, fun .Polar (p35,0,0.1)), new Line(p35, p34), dconms *1.5, 0.8 * scale, 1.2 * scale, 0.9, "KAPR", "", "");
            fun.Axis(dxf, v1, 180, 90, "Z", "X", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Axis(dxf, v2, 180, 90, "Y", "Z", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Axis(dxf, v3, 180, -90, "Z", "X", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Axis(dxf, p33 , 180, 90, "Y", "X", "", 0.2 * scale, 0.8 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v4, 130, fun.Polar(v4, 130 * pi / 180, dconms  / 4.0), fun.Polar(v4, 130 * pi / 180,dconms/2.0 ), 0.8 * scale, 1.2 * scale);
            fun.Singlelinearrow(dxf, "FDP", v5 , 0, fun.Polar(v5, 180 * pi / 180, dconms / 4.0), fun.Polar(v5, 180 * pi / 180, dconms/2.0), 0.8 * scale, 1.2 * scale);
            Line linev1 = new Line(v7, v6);
            Line linev2 = new Line(v9, v8);
            Line linev3 = new Line(v10, v11);
            Line linev4 = new Line(v12, v13);
            Line linev5 = new Line(v15, v16);
            Line linev6 = new Line(v19, v18);
            Text txt1 = new Text("PCS,MCS", v8, 0.8 * scale, 0);
            Text txt2 = new Text("CSW", v11, 0.8 * scale, 0);
            Text txt3 = new Text("CRP", v14, 0.8 * scale, 0);
            Text txt4 = new Text("CSW", v17, 0.8 * scale, 0);
            Text txt5 = new Text("CRP", v20, 0.8 * scale, 0);
            Text txt6 = new Text("ISYC=309_07", fun .Polar (p4,pi/2,dconms /2.0), 0.8 * scale, 0);
            Circle circle1 = new Circle(p26, 0.2 * 1.7 * scale);
            Circle circle2 = new Circle(p35, 0.2 * 1.7 * scale);
            dxf.AddEntity(new EntityObject[] { linev1,linev2,linev3,linev4,linev5,linev6 
            ,txt1 ,txt2,txt3,txt4,txt5,txt6
            ,circle1 ,circle2 
            });

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //图F.98  ISYC 309-07-法兰接触式连接的可转位刀片外车削系统
        public static void ISYC_309_07_j(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            // double sl_ = Convert.ToDouble(data["oal"]);
            // double scale = Convert.ToDouble(data["scale"]);
            double sl_ = 45;
            double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dconms = 10 * scale;
            double wf = 6.37 * scale;
            double wfa = 3.47 * scale;
            double lf = 12.41 * scale;
            double lpr = 13.33 * scale;
            double oal = 18.73 * scale;
            double kapr = 75;
            double kapr_ = kapr * pi / 180;
            double lfa = lpr - lf;
            */
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double wfa = Convert.ToDouble(data["wfa"]) * scale;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lpr = Convert.ToDouble(data["lpr"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]);
            double kapr_ = kapr * pi / 180;
            double lfa = lpr - lf;
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //柄部
            Vector2 p0 = new Vector2(0, 0);
            Vector2[] vis(Vector2 p)
            {
                Vector2 p1_0; Vector2 p2_0; Vector2 p3_0; Vector2 p4_0; Vector2 p5;
                p1_0 = fun.Polar(p, pi / 2, dconms / 2.0);
                p2_0 = fun.Polar(p, pi / -2, dconms / 2.0);
                p3_0 = fun.Polar(p2_0, pi, 4.2 / 19.54 * lpr);
                p4_0 = fun.Polar(p1_0, pi, fun.CalDistance(p2_0, p3_0));
                p5 = fun.Polar(p3_0, pi / 2, dconms / 12.5);
                Vector2 p6 = fun.Polar(p5, pi - 5 * pi / 180, ((oal - lpr) / Math.Cos(5 * pi / 180)) - ((0.4 / 4.96) * (oal - lpr)));
                Vector2 p7_0 = fun.Polar(fun.Polar(p5, pi / 2, fun.CalDistance(p4_0, p5) / 2.0), pi, oal - lpr);
                Vector2 p7_1 = fun.Polar(p7_0, pi / 2, dconms);
                Vector2 p7_2 = fun.Polar(p7_0, pi / -2, dconms);
                Vector2 p7_3 = fun.Polar(p6, fun.CalAngle(p5, p6) - pi / 4, dconms);
                Vector2 p7_4 = fun.Inters(p6, p7_3, p7_1, p7_2);
                Vector2 p8_0 = fun.Polar(p4_0, pi / -2, fun.CalDistance(p3_0, p5));
                Vector2 p9_0 = fun.Polar(p8_0, pi + 5 * pi / 180, fun.CalDistance(p5, p6));
                Vector2 p10_0 = fun.Polar(p9_0, (-fun.CalAngle(p6, p7_4)), fun.CalDistance(p6, p7_4));
                var polyline1 = Pus.AddPointsToLwPolyLine(p8_0, p4_0, p1_0, p2_0, p3_0, p8_0, p9_0, p10_0, p7_4, p6, p9_0, p6, p5);
                Line line2 = new Line(fun.Polar(p, pi, p1_0.X + (oal - lpr) + 15), fun.Polar(p, 0, lpr + 15));
                line2.Lineweight = Lineweight.W25;//Lineweight指线宽
                line2.Layer = centre;//Layer指图层
                line2.LinetypeScale = 5 * scale;//指线性比例
                if (p.Y == 0)
                    line2.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                else
                    line2.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line2); //提取
                fun.PolyFill(dxf, polyline1, 0.5, contour);
                Vector2[] pj = { p1_0, p2_0, p3_0, p4_0, p5, p6, p7_4, p8_0, p9_0, p10_0 };
                return pj;
            }

            /*Vector2[] pj_1 = vis(p0);
            Vector2 p1 = pj_1[0];
            Vector2 p2 = pj_1[1];
            Vector2 p3 = pj_1[2];
            Vector2 p4 = pj_1[3];

            Vector2 p11 = fun.Polar(p2, pi / -2, fun.CalDistance(p1, p2) * (0.6 / 10.0));
            Vector2 p12 = fun.Polar(p1, 0, fun.CalDistance(p1, p4) * (0.57 / 3.68));
            Vector2 p13 = new Vector2(-fun.CalDistance(p1, p4) + lpr - lfa / 2.0, 0);
            Vector2 p14 = fun.Polar(p13, pi, lpr * (6.766 / 13.22));
            Vector2 p15 = fun.Polar(p13, pi / -2, (1.13 / 10.0) * dconms);
            Vector2 p16 = fun.Polar(p15, pi, (0.37 / 13.22) * lpr);
            Vector2 p17 = fun.Polar(p16, -97 * pi / 180, dconms * (1.71 / 10.0));
            Vector2 p18_1 = fun.Polar(p11, 0, lpr);
            Vector2 p18_2 = fun.Polar(p17, -112 * pi / 180, lpr);
            Vector2 p18 = fun.Inters(p11, p18_1, p17, p18_2);
            Vector2 p19 = fun.Polar(p13, pi, (2.79 / 13.22) * lpr);
            Vector2 p20 = fun.Inters(p19, fun.Polar(p19, pi / -2, dconms), p11, p18);
            Vector2 p21 = fun.Polar(p14, 0, (1.63 / 13.22) * lpr);
            Vector2 p22 = fun.Inters(p11, p18, p21, fun.Polar(p21, pi / -2, dconms));
            Vector2 p23 = fun.Polar(p21, pi, (0.92 / 13.22) * lpr);
            Vector2 p24 = fun.Inters(p11, p18, p23, fun.Polar(p23, pi / -2, dconms));
            Vector2 p25 = fun.Inters(p19, p20, p15, fun.Polar(p15, pi, dconms));
            Vector2 p26 = fun.Polar(p13, pi, (0.89 / 13.22) * lpr);
            Vector2 p27 = fun.Inters(p25, p15, p26, fun.Polar(p26, pi / -2, dconms));
            Vector2 arc1_1 = fun.Polar(p23, pi, fun.CalDistance(p11, p24) / 3.0);
            Vector2 arc1_2 = fun.Polar(arc1_1, pi - pi / 3, dconms);
            */

            //第二部分
            //柄部
            Vector2 p0_0 = fun.Polar(p0, pi / -2, dconms * 2);
            Vector2[] pj_2 = vis(p0_0);
            Vector2 p1_10 = pj_2[0];
            Vector2 p2_10 = pj_2[1];
            Vector2 p3_10 = pj_2[2];
            Vector2 p4_10 = pj_2[3];
            Vector2 p5_10 = pj_2[4];
            Vector2 p6_10 = pj_2[5];
            Vector2 p7_10 = pj_2[6];
            Vector2 p8_10 = pj_2[7];
            Vector2 p9_10 = pj_2[8];
            Vector2 p10_10 = pj_2[9];
            Vector2 p28 = new Vector2(-fun.CalDistance(p1_10, p4_10) + lpr - lfa / 2.0, p0_0.Y);
            Vector2 p29 = fun.Polar(p28, pi / 2, (0.67 / 10.0) * dconms);
            Vector2 p30_1 = fun.Polar(p29, pi - pi / 4, dconms);
            Vector2 p30_2 = fun.Polar(p1_10, 0, dconms);
            Vector2 p30 = fun.Inters(p1_10, p30_2, p29, p30_1);
            Vector2 p31 = fun.Polar(p2_10, pi / -6, (1 / 13.33) * lpr);
            Vector2 p32_1 = fun.Polar(p28, pi / -2, dconms);
            Vector2 p32_2 = fun.Polar(p31, 0, dconms);
            //切削部分
            Vector2 p32 = fun.Inters(p31, p32_2, p28, p32_1);
            Vector2 p33 = fun.Polar(p32, pi - pi / 4, (wfa / 4.0) / Math.Cos(pi / 4));
            Vector2 p34 = fun.Polar(p33, pi / 2 - pi / 4 - (pi / 2 - kapr_), (wfa / 2.0) / (Math.Cos(pi / 4)));
            Vector2 p35 = fun.Polar(p34, kapr_ - pi, wfa);
            Vector2 p36 = fun.Polar(p35, fun.CalAngle(p35, p34) + pi / 2, wfa);
            Vector2 p37 = fun.Polar(p36, fun.CalAngle(p36, p35) + pi / 2, wfa);
            Vector2 p38 = fun.Inters(p34, p37, p28, fun.Polar(p28, pi / -2, dconms));
            Vector2 p39 = fun.Inters(p36, p37, p31, fun.Polar(p31, 0, dconms));

            /*
            Arc arc1 = fun.DrawArc5(p12, new Line(arc1_1, arc1_2), p14);
            var polyline2 = Pus.AddPointsToLwPolyLine(p12, p1, p11, p24, p23, p21, p22, p24, p20, p19, p13, p15, p27, p25, p27,
                p26, p19, p20, p18, p17, p16, p15, p13, p14);*/
            var polyline3 = Pus.AddPointsToLwPolyLine(p1_10, p30, p29, p38, p37, p36, p35, p34,
              p37, p39, p31, p2_10);
            /*dxf.AddEntity(new EntityObject[] { polyline2,polyline3,
                 arc1 
             });*/
            //fun.PolyFill(dxf, polyline2, 0.5, contour);
           // fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            //标注
            /* fun.dimrot1(dxf, p1, p18, 90, dc, 2, 2 * scale, 2.4 * scale, 0.9, "DCB", "", "");
       fun.jdbz2(dxf, new Line(p4, p5), new Line(p7, p8), dc, 2 * scale, 2.4 * scale, 0.9, "SIG", "", "");
       fun.Axis(dxf, fun.Polar(p0, pi + pi / 3, dc * 2), 180, -90, "Z", "X", "Y", 1 * scale, 2 * scale, 0);
       fun.Axis(dxf, p0, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
       fun.Axis(dxf, p19, 180, -90, "", "", "", 1 * scale, 2 * scale, 0);
       fun.Singlelinearrow(dxf, "CCMS", v1, 110, fun.Polar(v1, 110 * pi / 180, dc / 2.0), fun.Polar(v1, 110 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
       Text txt1 = new Text("PCS", v18, 2.2 *scale , 0);
       Circle circle1 = new Circle(p0, 1.7 * 2 * scale) ;
             */
            Vector2 v4 = fun.Polar(p9_10, fun.CalAngle(p9_10, p8_10), fun.CalDistance(p9_10, p8_10) * (2 / 3.0));
            //fun.dimrot1(dxf, p26, fun.Polar(p26, pi / -2, 0.1), -90, dconms / 2.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "HF,HTA", "", "");
            fun.dimrot1(dxf, p3_10, p4_10, 90, dconms, 2, 0.8 * scale, 1.2 * scale, 0.9, "DCON", "", "");
            fun.dimrot1(dxf, p28, p35, -90, dconms, 2, 0.8 * scale, 1.2 * scale, 0.9, "WF", "", "");
            //fun.dimrot1(dxf, p34, p35, -90, dconms / 2.0, 2, 0.8 * scale, 1.2 * scale, 0.9, "WF,WTA", "", "");
            //fun.dimrot1(dxf, p35, p34, 180, dconms * 1.5 + ((p35.Y - p34.Y) / 2.0) + (p34.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LFA", "", "");
            fun.dimrot1(dxf, p3_10, p35, 180, dconms * 1.5 + ((p35.Y - p3_10.Y) / 2.0) + (p3_10.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LF", "", "");
            fun.dimrot1(dxf, p3_10, p34, 180, dconms * 1.8 + ((p3_10.Y - p34.Y) / 2.0) + (p34.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p7_10, p34, 180, dconms * 2.0 + ((p7_10.Y - p34.Y) / 2.0) + (p34.Y - p28.Y), 2, 0.8 * scale, 1.2 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p1_10, p34, 0, dconms , 2, 0.8 * scale, 1.2 * scale, 0.9, "LH", "", "");
            fun.jdbz2(dxf, new Line(p35, fun.Polar(p35, 0, 0.1)), new Line(p35, p34), dconms * 1.5, 0.8 * scale, 1.2 * scale, 0.9, "KAPR", "", "");
            fun.jdbz2(dxf, new Line(p35, p34), new Line(p35, p36), dconms , 0.8 * scale, 1.2 * scale, 0.9, "EPSR", "", "");
            fun.Singlelinearrow(dxf, "CCTMS,CCFMS,CZCMS", v4, 130, fun.Polar(v4, 130 * pi / 180, dconms / 2.0), fun.Polar(v4, 130 * pi / 180, dconms ), 0.8 * scale, 1.2 * scale);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}


